﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EM.Repository.utility;
using System.Data;
using System.Data.SqlClient;

namespace EM.operation.project
{
    public partial class _default : System.Web.UI.Page
    {
        FillCombo fc = new FillCombo();


        protected void Page_Load(object sender, EventArgs e)
        {
            Authentication ua = new Authentication();
            ua.CheckRolePageAuthentication(36, Authentication.RedirectionURLTypes.LoginPage);


            if (!IsPostBack)
            {
                fc.LookUpValue(ddlStatus, "", true, "PROJECT_STATUS", Session["LANGCODE"].ToString());
            }

        }
        private DataTable GetData()
        {
            SqlCommand cmd = new SqlCommand();
            string sSQL = "";
            sSQL += @"SELECT PROJECTID,PROJECTCODE,PROJECTDESC,
                        PROJECTSTATUS,LVL.LOOKUPNAME PROJECTSTATUSNAME  FROM TBLPROJECT P, TBLLOOKUPVALUE_L LVL
                        WHERE P.PROJECTSTATUS = LVL.LOOKUPVALUE AND LVL.LANGCODE = @LANGCODE AND LVL.LOOKUPTYPE = 'PROJECT_STATUS'";

            if (txtProjectCode.Text.Trim() != "")
            {
                sSQL += " AND P.PROJECTCODE = @PROJECTCODE ";
                cmd.Parameters.AddWithValue("@PROJECTCODE", txtProjectCode.Text.Trim());
            }

            if (txtProjectDesc.Text.Trim() != "")
            {
                sSQL += " AND P.PROJECTDESC LIKE @PROJECTDESC ";
                cmd.Parameters.AddWithValue("@PROJECTDESC", "%" + txtProjectDesc.Text.Trim() + "%");
            }

            if (ddlStatus.SelectedValue != "")
            {
                sSQL += " AND P.PROJECTSTATUS = @PROJECTSTATUS ";
                cmd.Parameters.AddWithValue("@PROJECTSTATUS", ddlStatus.SelectedValue);
            }

            cmd.Parameters.AddWithValue("@LANGCODE", Session["LANGCODE"]);
            cmd.CommandText = sSQL;

            DataTable dt = new DataTable();
            DbHelper dsrv = new DbHelper();

            dt = dsrv.GetDataTable(cmd, "TBL");
            return dt;
        }

        protected void rgMaster_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e)
        {
            DataTable dt = GetData();
            rgMaster.DataSource = dt;

            rgMaster.MasterTableView.NoMasterRecordsText = "Kayıt bulunamadı.";
            rgMaster.StatusBarSettings.ReadyText = dt.Rows.Count + " adet kayıt bulundu.";
        }


        protected override void RaisePostBackEvent(IPostBackEventHandler source, String eventArgument)
        {
            base.RaisePostBackEvent(source, eventArgument);
            switch (eventArgument)
            {
                case "Rebind":
                    rgMaster.Rebind();
                    break;
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            rgMaster.Rebind();

        }

    }
}